<template>
	<a-card :bordered="false">
		<div class="table-page-search-wrapper">
			<a-form layout="inline">
				<a-row :gutter="48">

					<a-col :md="8" :sm="24">
						<a-form-item label="生产单号">
							<a-input v-model="queryParam.orderNumber" placeholder="请输入生产单号" />
						</a-form-item>
					</a-col>
					<a-col :md="24" :sm="24" v-if="!isFour()">
						<a-form-item label="归属公司：">
							<FCOrgRadioGroup v-model="queryParam.orgId" :filter-types="[$businessEnum.ORG_TYPE_ENUM.COMPANY.id]" />
							<!--              <a-radio-group default-value="" button-style="solid" v-model="queryParam.orgIdCompany">-->
							<!--                <a-radio-button value="">-->
							<!--                  全部-->
							<!--                </a-radio-button>-->
							<!--                <a-radio-button :value="id" v-for="{id, name} in orgs">-->
							<!--                  {{ name }}-->
							<!--                </a-radio-button>-->
							<!--              </a-radio-group>-->

						</a-form-item>
					</a-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="物料编号">
							<a-input v-model="queryParam.jzMaterialCode" placeholder="请输入物料编号" />
						</a-form-item>
					</a-col>
					<el-col :md="7" :sm="6">
						<a-form-item label="状 态">							
							<a-radio-group default-value="" button-style="solid" v-model="queryParam.scckStatus">
								<a-radio-button value="">全部</a-radio-button>
								<a-radio-button value="1">待出库</a-radio-button>
								<a-radio-button value="2">出库中</a-radio-button>
								<!-- <a-radio-button value="3">己出库</a-radio-button> -->
							</a-radio-group>
						</a-form-item>
					</el-col>
					<a-col :md="8" :sm="24">
						<a-form-item label="领用方">
							<a-select placeholder="全部" v-model="queryParam.classGroupId">
								<!-- <a-select-option :value="null">
									全部
								</a-select-option> -->
								<a-select-option :values="item.classGroupId" v-for="item in teamList" :key="item.classGroupId">
									{{ item.name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :md="!advanced && 8 || 24" :sm="24">
						<span class="table-page-search-submitButtons"
							:style="advanced && { float: 'right', overflow: 'hidden' } || {}">
							<a-button type="primary" @click="table.refresh(true)">查询</a-button>
							<a-button style="margin-left: 8px" @click="handleResetSearch">重置</a-button>
						</span>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div style="margin: 10px 0px;">
			<Export text="出库单导出" v-if="hasBtnPremission(['emsBom:export'])" title="出库单导出" url="/emsBom/export"
			:isBody="true"
				:obj="{
					
				}" />
		</div>
		<s-table ref="table" size="default" :columns="columns" :data="loadData" :alert="true"
			:rowKey="(record) => record.code" :rowSelection="null">
			<span slot="scckStatus" slot-scope="text, record">
				<a-tag color="#F56C6C" v-if="record.scckStatus == 1"> 待出库 </a-tag>
				<a-tag color="#108ee9" v-if="record.scckStatus == 2"> 出库中 </a-tag>
				<!-- <a-tag color="#87d068" v-if="record.scckStatus == 3"> 己出库 </a-tag> -->
			</span>
			<span slot="action" slot-scope="text, record">
				<a @click="outStoreEditForm.show(record)">出库</a>
				<a-divider type="vertical" />
				<a @click="$refs.outStoreRecordModal.show(record)">出库详情</a>
				<a-divider type="vertical" v-if="hasPerm('emsOrderMaterial:page')" />
				<a @click="backStore.show(record)" v-if="hasPerm('emsOrderMaterial:page')">退库</a>
				<a-divider type="vertical" />
				<a @click="backStoreRecordDetailModal.show(record)">退库入库单明细</a>
				<a-divider type="vertical" />
				<a @click="$refs.editRemark.show(record, materialType)">备注</a>
			</span>
		</s-table>

		<out-store-edit-form ref="outStoreEditForm" @ok="handleOk" />
		<out-store-record-modal ref="outStoreRecordModal" />
		<back-store ref="backStore" />
		<back-store-record-detail-modal ref="backStoreRecordDetailModal" />
		<edit-remark ref="editRemark" @ok="table.refresh(true)" />
	</a-card>
</template>

<script lang="ts">
import { Component, Vue, Ref } from "vue-property-decorator";
import { STable } from '@/components'
import { page } from '@/api/modular/main/emsorder/emsOrderManage'
import FCOrgRadioGroup from '@/components/FcOrgRadioGroup/FCOrgRadioGroup.vue'
import OutStoreEditForm from './outStoreEditForm.vue'
import OutStoreRecordModal from './outStoreRecordModal.vue'
import BackStore from './backStore.vue'
import BackStoreRecordDetailModal from './backStoreRecordDetailModal.vue'
import EditRemark from "./editRemark.vue";

import { page as teamPage } from '@/api/modular/main/classGroup/classGroup'

@Component({
	components: {
		OutStoreRecordModal,
		FCOrgRadioGroup,
		OutStoreEditForm,
		STable,
		BackStore,
		BackStoreRecordDetailModal,
		EditRemark
	}
})
export default class PackingProductionOrderByWaitOutStore extends Vue {
	@Ref() readonly table!: any
	@Ref() readonly backStore!: BackStore
	@Ref() readonly outStoreEditForm!: OutStoreEditForm
	@Ref() readonly backStoreRecordDetailModal!: BackStoreRecordDetailModal

	advanced = false // 高级搜索 展开/关闭
	columns = [
		{
			title: '序号', width: '80px',
			customRender: (text, record, index) => `${index + 1}`
		},
		{
			title: '生产单号',
			dataIndex: 'orderNumber'
		},
		{
			title: '状态',
			dataIndex: 'scckStatus',
			scopedSlots: { customRender: 'scckStatus' }
		},
		{
			title: '备注',
			dataIndex: 'bcScckRemark',
			ellipsis: true
		},
		{
			title: '开始时间',
			dataIndex: 'createTime'
		},
		{
			title: '操作',
			dataIndex: '',
			width: '360px',
			scopedSlots: { customRender: 'action' }
		}
	]
	queryParam = {
		orgId: '',
		orderNumber: '',
		orderType: '',
		executeStatus: '',
		classGroupId: undefined,
		jzMaterialCode: '',
		scMaterialType: null
	}
	selectedRowKeys = []
	selectedRows = []

	materialType = this.$businessEnum.MATERIAL_TYPE_ENUM.packing.id

	// 加载数据方法 必须为 Promise 对象
	loadData(parameter: { pageNo: number, pageSize: number }) {
		this.queryParam.orderType = this.$businessEnum.ORDER_TYPE_ENUM.produceOrder.id
		this.queryParam.executeStatus = this.$businessEnum.EXECUTE_STATUS_ENUM.IN_PROGRESS.id
		this.queryParam.scMaterialType = this.materialType
		// 由于包材查询时需要包含未添加包材的生产单,所以不能加物料类型筛选条件
		return page(Object.assign(parameter, this.queryParam)).then((res) => {
			return res.data
		})
	}
	created() {
		console.log('111')
		this.getTeamList();
	}

	toggleAdvanced() {
		this.advanced = !this.advanced
	}

	handleOk() {
		this.table.refresh()
		this.table.clearSelected()
	}
	teamList = [];
	//获取领用方
	getTeamList() {
		teamPage({
			pageSize: -1,
			status: 0
		}).then(res => {
			this.teamList = res.data.rows;
		})
	}
	handleResetSearch() {
		this.queryParam = {
			orgId: '',
			orderNumber: '',
			orderType: '',
			executeStatus: '',
			classGroupId: undefined,
			jzMaterialCode: '',
			scMaterialType: null
		}
		this.handleOk()
	}

	onSelectChange(selectedRowKeys, selectedRows) {
		this.selectedRowKeys = selectedRowKeys
		this.selectedRows = selectedRows
	}

	//总经理，以及四个仓库的管理员    返回true
	isFour() {
		return this.hasRole(this.$util.ROLE_ENUM.SQCG.id)   //采购
	}
}
</script>

<style lang="less">
.table-operator {
	margin-bottom: 18px;
}

button {
	margin-right: 8px;
}
</style>
